package com.zzg.test2.web.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import com.zzg.test2.R
import com.zzg.test2.web.TabWebJsFragment

class JumpFragment : Fragment() {

    private var tabWebJsFragment: TabWebJsFragment? = null

//    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
//        // 创建一个带 ID 的容器视图
//        val frameLayout = FrameLayout(requireContext()).apply {
//            id = View.generateViewId()
//            layoutParams = ViewGroup.LayoutParams(
//                ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.MATCH_PARENT
//            )
//        }
//
//        return frameLayout
//    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_jump, container, false)
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // 创建并添加 TabWebJsFragment
        createAndAddTabWebJsFragment()
    }

    private fun createAndAddTabWebJsFragment() {
        // 检查是否已经添加过

        if (tabWebJsFragment == null) {
            // 创建 TabWebJsFragment 实例
            tabWebJsFragment = TabWebJsFragment.newInstance("https://www.leadfund.com.cn/html5/index/advicer")

        }
        // 使用 FragmentTransaction 添加到当前 Fragment 中
        childFragmentManager.beginTransaction()
            .replace(R.id.container, tabWebJsFragment!!)
            .commit()
    }

    // 可选：提供重新加载方法
    fun reloadWebView(url: String) {
        tabWebJsFragment?.reloadWebView(url)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        tabWebJsFragment = null
    }
}